<template>
  <!--  头部-->
  <div class="header">
    <div class="header-left">
      中部地区
      <van-icon name="arrow"/>
    </div>
    <van-search v-model="searchValue" placeholder="请输入搜索关键词"/>
  </div>
  <!--  轮播图-->
  <van-swipe class="my-swiper" height="170" :autoplay="3000" indicator-color="white">
    <van-swipe-item
        v-for="item in homeData.slides"
        :key="item.id">
      <!--      图片-->
      <van-image
          radius="5"
          :src="item.pic_image_url"
      />
    </van-swipe-item>
  </van-swipe>
  <!--  快捷入口显示-->

  <van-row justify="space-around">
    <van-col
        span="11"
        v-for="(item,index) in homeData.nav2s"
        :key="item.id"
        class="center-img"
        @click="goOrderTwo(index)"
    >
      <!--      图片-->
      <van-image
          :src="item.pic_image_url"
      />

    </van-col>
  </van-row>

  <!-- 医院列表-->

  <van-row
      justify="space-around"
      class="yy-list"
      @click="goOrder(item)"
      v-for="(item,index) in homeData.hospitals">
    <!--    左边-->
    <van-col span="6">
      <!--  图片-->
      <van-image
          width="100"
          height="90"
          :src="item.avatar_url"
      />
    </van-col>
    <!--    右边-->
    <van-col
        span="15"
        class="yy"
    >
      <div class="yy-name">{{ item.name }}</div>
      <div class="yy-type">
        <span>{{ item.rank }} </span>
        &nbsp;
        <span>{{ item.label }}</span>
      </div>
      <div class="yy-text">{{ item.intro }}</div>
    </van-col>

  </van-row>

</template>
<script setup>
import {ref, reactive, onMounted, getCurrentInstance} from 'vue'
import {useRouter} from 'vue-router'
// 获取当前实例 (当前组件实例)
const {proxy} = getCurrentInstance()
// 搜索框的值
const searchValue = ref('')
// 获取首页数据
const homeData = reactive({
  hospitals: [], // 医院列表
  nav2s: [], // 导航列表
  navs: [], // 导航列表
  now: "", // 当前时间
  slides: [], // 轮播图

})
// 跳转到医院详情
const goOrder = (item) => {
  router.push(`/createOrder?id=${item.id}`)

}
// 跳转到二级页面
const router = useRouter()
const goOrderTwo = (index) => {
  router.push(`/createOrder?id=${homeData.hospitals[index].id}`)

}
// 初始化数据
onMounted(async () => {
  const {data} = await proxy.$api.index()
  // 属性合并
  Object.assign(homeData, data.data)
})
</script>

<style lang="less" scoped>
.header {
  display: flex;
  justify-content: space-between;
  margin: 5px;
  line-height: 54px;

  .header-left {
    padding-left: 22px;
    background: url(../../assets/images/result.png) no-repeat left center;
    background-size: 20px;
    font-size: 20px;
    font-weight: bold;
    color: #666666;
  }
}

.my-swiper {
  margin: 5px;
}

.yy-list {
  padding-bottom: 10px;
  margin: 20px 0;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.04);

  .yy {
    .yy-name {
      font-size: 20px;
      line-height: 30px;
      font-weight: bold;
    }

    .yy-type {
      font-weight: bold;
      line-height: 25px;
      font-size: 15px;
      color: #0ca7ae;
    }

    .yy-text {
      font-size: 14px;
      color: #999999;
    }
  }
}

.bottom-text {
  line-height: 50px;
  text-align: center;
  color: #999999;
}


</style>
